interface BettingType{
    name: string,
    id: number
}

class Main {
    count: number
    remind: any
    roundCount: number
    time: any
    constructor() {
    }
    constellation(angle: number): BettingType {// 返回星座下注点
        let a: BettingType;
        switch (angle) {
            case 1:
                a = { name: "白羊", id: 1 };
                break;
            case 2:
                a = { name: "金牛", id: 2 };
                break;
            case 3:
                a = { name: "双子", id: 3 };
                break;
            case 4:
                a = { name: "巨蟹", id: 4 };
                break;
            case 5:
                a = { name: "狮子", id: 5 };
                break;
            case 6:
                a = { name: "处女", id: 6 };
                break;
            case 7:
                a = { name: "天秤", id: 7 };
                break;
            case 8:
                a = { name: "天蝎", id: 8 };
                break;
            case 9:
                a = { name: "射手", id: 9 };
                break;
            case 10:
                a = { name: "摩羯", id: 10 };
                break;
            case 11:
                a = { name: "水瓶", id: 11 };
                break;
            case 12:
                a = { name: "双鱼", id: 12 };
                break;
        }
        return a;
    }
    elements(angle: number): BettingType {// 返回五行下注点
        let a: BettingType;
        switch (angle) {
            case 1:
                a = { name: "金", id: 1 };
                break;
            case 2:
                a = { name: "木", id: 2 };
                break;
            case 3:
                a = { name: "水", id: 3 };
                break;
            case 4:
                a = { name: "火", id: 4 };
                break;
            case 5:
                a = { name: "土", id: 5 };
                break;
        }
        return a;
    }
    gender(angle: number): BettingType {// 返回五行下注点
        let a: BettingType;
        switch (angle) {
            case 1:
                a = { name: "金童", id: 1 };
                break;
            case 2:
                a = { name: "玉女", id: 2 };
                break;
        }
        return a;
    }
    difference(quadrant: number, x: number, y: number, left: number, top: number, radius: number ) :{x: number, y: number}{// 计算角度差值
        let data = { x, y }
        switch (quadrant) {
            case 1:
                data.y = (top + radius * 2) -  (y - top);
                break;
            case 2:
                data.x = (left + radius * 2) - (x - left);
                data.y = (top + radius * 2) - (y - top);
                break;
            case 3:
                data.x = (left + radius * 2) - (x - left);
                break;
        }
        return data;
    }
    fixed(angle: number, radius: number): {quadrant: number, angle: number}{// 计算象限
        let quadrant: number = Math.floor(angle / 90),
            roundAngle :number = angle % 90;
        roundAngle == 0 && (quadrant -= 1, roundAngle=90);
        roundAngle = roundAngle == 90 ? 90 : angle < 90 || (angle > 180 && angle < 269) ? roundAngle : 90 - roundAngle;
        if (angle <= 90 ){
            roundAngle = angle; 
        }
        return { quadrant, angle: roundAngle};
    }
    angle(_self: any | object, angle: number, roundCount: number) :{x: number, y:number}{// 位置结果
        this.roundCount = _self.game.rem(roundCount);
        let round = window.getComputedStyle(_self.$refs.gameApp),
            radius = Number(round.width.split("px")[0]) / 2 - this.roundCount,
            top = Number(round.top.split("px")[0]);
        if (angle == 0) {
            return { x: radius + this.roundCount, y: top + this.roundCount };
        }
        if (angle == 180) {
            return { x: radius + this.roundCount, y: top + (radius*2) + this.roundCount };
        }
        let data = this.fixed(angle, radius),
            tan = Math.tan(data.angle * Math.PI / 180),
            a = (radius * tan) / Math.sqrt(tan * tan + 1),
            x = radius + a + this.roundCount,
            y = top + ( radius + this.roundCount - a/tan );
         
        var positon: { x: number, y: number } = this.difference(data.quadrant, x, y, this.roundCount, top + this.roundCount, radius);
        return {x: positon.x, y: positon.y};
    }
    scrollBar(type: number, id: number) :{name:string, position: string}{// 结果函数
        let a :{ name: string, position: string } = { name: "", position:"0"};
        if(type === 1){
            a.name = this.constellation(id).name;
            a.position = -(11.7 + 0.325 * (id - 1) - 0.01) + "rem";
        } else if (type === 2) {
            a.name = this.elements(id).name;
            a.position = -(11.375 + 0.325 * (id - 1) - 0.01) + "rem";
        } else {
            a.name = this.gender(id).name;
            a.position = -(6.45 + 0.325 * (id - 1) - 0.01) + "rem";
        }
        return a;
    }
    countDown( callback: ()=>void ) :void{// 倒计时
        clearInterval(this.time);
        this.time = setInterval(()=>{
            this.count -= 1;
            if(this.count == 4){
                this.remind.end = true;
            }
            if (this.count == 0) {
                this.remind.end = false;
                callback.call(this);
            }
        }, 1000)
    }
}

export default Main;